package com.zhongruan.zrccddllyhn.service.impl;

import com.zhongruan.zrccddllyhn.mapper.UserMapper;
import com.zhongruan.zrccddllyhn.pojo.User;
import com.zhongruan.zrccddllyhn.service.UserService;
import com.zhongruan.zrccddllyhn.utils.ThreadLocalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByUserName(String username) {
        return userMapper.findByName(username);
    }

    @Override
    public void addUser(String username, String password, String userId) {
        userMapper.add(username,password,userId);
    }

    @Override
    public void updatePwd(String newPwd) {
        Map<String,Object> map = ThreadLocalUtils.get();
        Integer id = (Integer) map.get("id");
        userMapper.upDatePwd(newPwd,id);
    }

    @Override
    public void updateCell(String nowCell) {
        Map<String,Object> map = ThreadLocalUtils.get();
        Integer id = (Integer) map.get("id");
        userMapper.updateCell(nowCell,id);
    }
}
